package com.esoon.service.impl;


import com.alibaba.druid.util.StringUtils;
import com.esoon.dao.CsrBlackListDao;
import com.esoon.entity.CsrBlackList;
import com.esoon.service.CsrBlackListService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 名单管理(CsrBlackList)表服务实现类
 *
 * @author makejava
 * @since 2020-09-22 12:03:58
 */
@Service
public class CsrBlackListServiceImpl implements CsrBlackListService {

    private static final Logger logger;

    static {
        logger = LoggerFactory.getLogger(CsrBlackListServiceImpl.class);
    }
    @Resource
    private CsrBlackListDao csrBlackListDao;


    @Override
    public int deleteByPrimaryKey(Integer blId) {
        return csrBlackListDao.deleteByPrimaryKey(blId);
    }

    @Override
    public int insert(CsrBlackList record) {
        return csrBlackListDao.insert(record);
    }

    @Override
    public int insertSelective(CsrBlackList record) {
        return csrBlackListDao.insertSelective(record);
    }

    @Override
    public CsrBlackList selectByPrimaryKey(Integer blId) {
        return csrBlackListDao.selectByPrimaryKey(blId);
    }


    @Override
    public int updateByPrimaryKeySelective(CsrBlackList record) {
        return csrBlackListDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(CsrBlackList record) {
        return csrBlackListDao.updateByPrimaryKey(record);
    }

    /*
     * @Author Jack
     * @Description //TODO 根据phonenumber查询出在COS-Dictionary表中的code字段的值，然后在service层做一次判断最后调用接口返回的就是int类型的数据
     * @Date 11:42 2020/9/24
     * @Param
     * @return
     *
     * dt_Code 目前有2种类型 1.red_phone 2.black_phone 3.空
     *         /*
            result = 0 查询成功 获取到的dtCode为OK时返回0
            result = 1 查询异常
            result = 2 初始内容，表示查询结束/当查询结果为“”时返回2
            result = 3 当获取到的dtCode为black_phone的时候，返回该值，表示查询到该电话号码为黑名单
            result = 4  当获取到的dtCode为red_phone的时候，返回该值，表示查询到该电话号码为红名单
         **/

    
    @Override
    public String selectByPhoneNumber(String blPhone, String tenantCode, String nowTime) {
        String result = "";
        try {
            Object dtCode = csrBlackListDao.selectByPhoneNumber(blPhone,tenantCode,nowTime);
            if(!StringUtils.isEmpty((String)dtCode)){
                switch (dtCode.toString()) {
                    case "red_phone":
                        result = "4";
                        logger.info("查询结果为红名单，返回4");
                        break;
                    case "black_phone":
                        result = "3";
                        logger.info("查询结果为黑名单，返回3");
                        break;
                    default:
                        result = "0";
                        logger.info("查询结果不为指定类型，返回0");
                        break;
                }
            }else{
                result = "500";
            }
        }catch (Exception e){
                result = "500";
                logger.error(e.toString());

        }
        return result;
    }
}